//
//  ChapterRequest.m
//  Cbchot
//
//  Created by 李雷川 on 2017/12/7.
//  Copyright © 2017年 王越. All rights reserved.
//

#import "ChapterRequest.h"
#import "iTools.h"
#import <CBCReader/CBCReader.h>
@interface ChapterRequest()<RequestBaseDelegate>

/**当前视频对象*/
@property (strong, nonatomic) Chapter *chapter;

@end
@implementation ChapterRequest
-(void)startRequest:(NSString*)bookID
         chapterNum:(NSUInteger)chapterNum
          chapterID:(NSString *)cahpterID
            success:(CAll_BACK) sucuessBack
               fail:(CAll_BACK) failBack{
    NSString* url = [NSString stringWithFormat:@"%@/api/book/get_chapter/",[iTools ServerHost]];
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
                         bookID ,@"book_id",
                          @(chapterNum) ,@"chapterNum",
                          cahpterID ,@"cahpterID",
                         nil];
    
    [self doPostRequest:url PostBody:dic Delegate:self];
}


/**解析数据*/
-(void)parserData:(NSDictionary *)dic
{
    NSLog(@"dic is:%@",dic);
    NSDictionary *chapterInfo = [dic valueForKey:@"chapterInfo "];
    if(chapterInfo != nil){
        self.chapter = [Chapter chapterWithDictionary:chapterInfo];
    }
}


/*联网解析完成*/
- (void)requestSuccess:(NSString*)message
{
    if(self.successBack){
        self.successBack(self.chapter);
    }
}

/*联网失败*/
- (void)requestFailed:(NSString *)errorMessage
{
    if(self.failBack){
        self.failBack(errorMessage);
    }
}

@end
